package app.authorization.dto;

import com.dj.gateway.app.utils.UrlEncoderUtils;
import lombok.Data;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;


@Data
@Slf4j
@ToString
public class MemberInfo implements Serializable {
    private static final long serialVersionUID = 477446729087580841L;

    private Integer id;

    /**
     * 会员名
     */
    private String name;

    /**
     * 会员姓名
     */
    private String realName;

    /**
     * 会员昵称
     */
    private String nickname;

    private String headImg;

    /**
     * 性别：0、未知 1、男 2、女
     */
    private Integer gender; // 默认值0;

    /**
     * 会员生日
     */
    private String birthday;

    /**
     * 身份证
     */
    private String idCard;

    private String qq;

    private String address;

    /**
     * 会员邮箱
     */
    private String email;

    /**
     * 工作类别，与member_job中id对应
     */
    private Integer jobId;

    /**
     * 对应member_level中id字段
     */
    private Integer memberLevelId;

    private MemberLevel memberLevel;

    /**
     * 会员卡
     */
    private String cardCode;

    private String remain1;

    private Long createTime;

    private Long modifyTime;

    private Long lastLoginTime;

    /**
     * 兑富值
     */
    private Integer wealth;

    /**
     * 状态为负值-1 无效,-3未激活,-2冻结
     */
    private Integer status;

    /**
     * 电子卡
     */
    private String eCardCode;

    private Integer isSms;

    /**
     * 有效积分消费金额，单位分
     */
    private Integer wealthAmount;

    private Long regTime;

    private String carPlate;

    /**
     * 车牌号修改时间
     */
    private Long carPlateModifyTime;

    /**
     * 唯一识别码
     */
    private String identificationCode;

    private MemberIdentity memberIdentity;

    private MemberCreditAccount memberCreditAccount;

    //当前会员已登录的设备 app,h5,miniapp
    private String loginDeviceStr;

    /**
     * 微信小程序openid
     */
    private String openId;

    /**
     * @return id
     */
    public Integer getId() {
        return id;
    }

    /**
     * @param id
     */
    public void setId(Integer id) {
        this.id = id;
    }

    /**
     * 获取会员名
     *
     * @return name - 会员名
     */
    public String getName() {
        return name;
    }

    /**
     * 设置会员名
     *
     * @param name 会员名
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取会员姓名
     *
     * @return real_name - 会员姓名
     */
    public String getRealName() {
        return realName;
    }

    /**
     * 设置会员姓名
     *
     * @param realName 会员姓名
     */
    public void setRealName(String realName) {
        this.realName = realName;
    }

    /**
     * 获取会员昵称
     *
     * @return nickname - 会员昵称
     */
    public String getNickname() {
        if (!StringUtils.isBlank(nickname) && UrlEncoderUtils.hasUrlEncoded(nickname)) {
            try {
                nickname = URLDecoder.decode(nickname, "utf-8");
                return nickname;
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        return nickname;
    }

    /**
     * 设置会员昵称
     *
     * @param nickname 会员昵称
     */
    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    /**
     * @return head_img
     */
    public String getHeadImg() {
//        return headImg;
//           headImg = ImageAliyunPathProcessor.processAliyunPath("mportal.member_info", "head_img", headImg,
//                "id", id);
//        if (StringUtils.isNotBlank(headImg) && headImg.endsWith(",")){
//            headImg = headImg.substring(0,headImg.length()-1);
//        }
        return headImg;
    }


    /**
     * @param headImg
     */
    public void setHeadImg(String headImg) {
//        this.headImg = ImageAliyunPathProcessor.processAliyunPath("mportal.member_info", "head_img", headImg,
//		        "id", id);
        this.headImg = headImg;
    }

    /**
     * 获取性别：0、未知 1、男 2、女
     *
     * @return gender - 性别：0、未知 1、男 2、女
     */
    public Integer getGender() {
        return gender;
    }

    /**
     * 设置性别：0、未知 1、男 2、女
     *
     * @param gender 性别：0、未知 1、男 2、女
     */
    public void setGender(Integer gender) {
        this.gender = gender;
    }

    /**
     * 获取会员生日
     *
     * @return birthday - 会员生日
     */
    public String getBirthday() {
        return birthday;
    }

    /**
     * 设置会员生日
     *
     * @param birthday 会员生日
     */
    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    /**
     * 获取身份证
     *
     * @return id_card - 身份证
     */
    public String getIdCard() {
        return idCard;
    }

    /**
     * 设置身份证
     *
     * @param idCard 身份证
     */
    public void setIdCard(String idCard) {
        this.idCard = idCard;
    }

    /**
     * @return qq
     */
    public String getQq() {
        return qq;
    }

    /**
     * @param qq
     */
    public void setQq(String qq) {
        this.qq = qq;
    }

    /**
     * @return address
     */
    public String getAddress() {
        return address;
    }

    /**
     * @param address
     */
    public void setAddress(String address) {
        this.address = address;
    }

    /**
     * 获取会员邮箱
     *
     * @return email - 会员邮箱
     */
    public String getEmail() {
        return email;
    }

    /**
     * 设置会员邮箱
     *
     * @param email 会员邮箱
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * 获取工作类别，与member_job中id对应
     *
     * @return job_id - 工作类别，与member_job中id对应
     */
    public Integer getJobId() {
        return jobId;
    }

    /**
     * 设置工作类别，与member_job中id对应
     *
     * @param jobId 工作类别，与member_job中id对应
     */
    public void setJobId(Integer jobId) {
        this.jobId = jobId;
    }

    /**
     * 获取对应member_level中id字段
     *
     * @return member_level_id - 对应member_level中id字段
     */
    public Integer getMemberLevelId() {
        return memberLevelId;
    }

    /**
     * 设置对应member_level中id字段
     *
     * @param memberLevelId 对应member_level中id字段
     */
    public void setMemberLevelId(Integer memberLevelId) {
        this.memberLevelId = memberLevelId;
    }

    public MemberLevel getMemberLevel() {
        return memberLevel;
    }

    /**
     * 获取会员卡
     *
     * @return card_code - 会员卡
     */
    public String getCardCode() {
        return cardCode;
    }

    /**
     * 设置会员卡
     *
     * @param cardCode 会员卡
     */
    public void setCardCode(String cardCode) {
        this.cardCode = cardCode;
    }

    /**
     * @return remain1
     */
    public String getRemain1() {
        return remain1;
    }

    /**
     * @param remain1
     */
    public void setRemain1(String remain1) {
        this.remain1 = remain1;
    }

    /**
     * @return create_time
     */
    public Long getCreateTime() {
        return createTime;
    }

    /**
     * @param createTime
     */
    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }

    /**
     * @return modify_time
     */
    public Long getModifyTime() {
        return modifyTime;
    }

    /**
     * @param modifyTime
     */
    public void setModifyTime(Long modifyTime) {
        this.modifyTime = modifyTime;
    }

    /**
     * @return last_login_time
     */
    public Long getLastLoginTime() {
        return lastLoginTime;
    }

    /**
     * @param lastLoginTime
     */
    public void setLastLoginTime(Long lastLoginTime) {
        this.lastLoginTime = lastLoginTime;
    }

    /**
     * 获取兑富值
     *
     * @return wealth - 兑富值
     */
    public Integer getWealth() {
        return wealth;
    }

    /**
     * 设置兑富值
     *
     * @param wealth 兑富值
     */
    public void setWealth(Integer wealth) {
        this.wealth = wealth;
    }

    /**
     * 获取状态为负值-1 无效,-3未激活,-2冻结
     *
     * @return status - 状态为负值-1 无效,-3未激活,-2冻结
     */
    public Integer getStatus() {
        return status;
    }

    /**
     * 设置状态为负值-1 无效,-3未激活,-2冻结
     *
     * @param status 状态为负值-1 无效,-3未激活,-2冻结
     */
    public void setStatus(Integer status) {
        this.status = status;
    }

    /**
     * 获取电子卡
     *
     * @return e_card_code - 电子卡
     */
    public String geteCardCode() {
        return eCardCode;
    }


    /**
     * 设置电子卡
     *
     * @param eCardCode 电子卡
     */
    public void setECardCode(String eCardCode) {
        this.eCardCode = eCardCode;
    }

    /**
     * @return is_sms
     */
    public Integer getIsSms() {
        return isSms;
    }

    /**
     * @param isSms
     */
    public void setIsSms(Integer isSms) {
        this.isSms = isSms;
    }

    /**
     * 获取有效积分消费金额，单位分
     *
     * @return wealth_amount - 有效积分消费金额，单位分
     */
    public Integer getWealthAmount() {
        return wealthAmount;
    }

    /**
     * 设置有效积分消费金额，单位分
     *
     * @param wealthAmount 有效积分消费金额，单位分
     */
    public void setWealthAmount(Integer wealthAmount) {
        this.wealthAmount = wealthAmount;
    }

    /**
     * @return reg_time
     */
    public Long getRegTime() {
        return regTime;
    }

    /**
     * @param regTime
     */
    public void setRegTime(Long regTime) {
        this.regTime = regTime;
    }

    /**
     * @return car_plate
     */
    public String getCarPlate() {
        return carPlate;
    }

    /**
     * @param carPlate
     */
    public void setCarPlate(String carPlate) {
        this.carPlate = carPlate;
    }

    /**
     * 获取车牌号修改时间
     *
     * @return car_plate_modify_time - 车牌号修改时间
     */
    public Long getCarPlateModifyTime() {
        return carPlateModifyTime;
    }

    /**
     * 设置车牌号修改时间
     *
     * @param carPlateModifyTime 车牌号修改时间
     */
    public void setCarPlateModifyTime(Long carPlateModifyTime) {
        this.carPlateModifyTime = carPlateModifyTime;
    }

    /**
     * 获取唯一识别码
     *
     * @return identification_code - 唯一识别码
     */
    public String getIdentificationCode() {
        return identificationCode;
    }

    /**
     * 设置唯一识别码
     *
     * @param identificationCode 唯一识别码
     */
    public void setIdentificationCode(String identificationCode) {
        this.identificationCode = identificationCode;
    }

    public MemberIdentity getMemberIdentity() {
        return memberIdentity;
    }

    public void setMemberIdentity(MemberIdentity memberIdentity) {
        this.memberIdentity = memberIdentity;
    }

    public MemberCreditAccount getMemberCreditAccount() {
        return memberCreditAccount;
    }

    public void setMemberCreditAccount(MemberCreditAccount memberCreditAccount) {
        this.memberCreditAccount = memberCreditAccount;
    }


    public void setIsScanLoginMember(Boolean isScanLogin) {
        if (memberIdentity == null) {
            memberIdentity = new MemberIdentity();
        }
        memberIdentity.setIsScanLoginMember(isScanLogin ? 1 : 0);
    }

    public Boolean getIsScanLoginMember() {
        if (memberIdentity != null) {
            return (memberIdentity.getIsScanLoginMember() != null && memberIdentity.getIsScanLoginMember() == 1) ? true : false;
        }
        return null;
    }

    public void setMob(Long mob) {
        if (memberIdentity == null) {
            memberIdentity = new MemberIdentity();
        }
        memberIdentity.setMob(mob);
    }

    public void setAppWxOpenid(String appWxOpenid) {
        if (memberIdentity == null) {
            memberIdentity = new MemberIdentity();
        }
        memberIdentity.setAppWxOpenid(appWxOpenid);
    }

    public void setMac(String mac) {
        if (memberIdentity == null) {
            memberIdentity = new MemberIdentity();
        }
        memberIdentity.setMac(mac);
    }

    public void setAccountName(String accountName) {
        if (memberIdentity == null) {
            memberIdentity = new MemberIdentity();
        }
        memberIdentity.setAccountName(accountName);
    }

    public String getAccountName() {
        if (memberIdentity != null) {
            return memberIdentity.getAccountName();
        }
        return null;
    }


    public void setPortalWxOpenid(String portalWxOpenid) {
        if (memberIdentity == null) {
            memberIdentity = new MemberIdentity();
        }
        memberIdentity.setPortalWxOpenid(portalWxOpenid);
    }

    public void setMiniAppOpenid(String miniAppOpenid) {
        if (memberIdentity == null) {
            memberIdentity = new MemberIdentity();
        }
        memberIdentity.setMiniAppOpenid(miniAppOpenid);
    }

    public void setPortallWxMsgOpenid(String portallWxMsgOpenid) {
        if (memberIdentity == null) {
            memberIdentity = new MemberIdentity();
        }
        memberIdentity.setPortalWxMsgOpenid(portallWxMsgOpenid);
    }

    public void setRegistSource(String registSource) {
        if (memberIdentity == null) {
            memberIdentity = new MemberIdentity();
        }
        memberIdentity.setRegistSource(registSource);
    }


    public void setMemberLevel(MemberLevel memberLevel) {
        this.memberLevel = memberLevel;
        if (memberLevel != null) {
            this.memberLevelId = memberLevel.getId();
        }
    }

    public void setAppId(String appId) {

        if (memberIdentity == null) {
            memberIdentity = new MemberIdentity();
        }
        memberIdentity.setAppId(appId);
    }

    public void setDeviceId(String deviceId) {
        if (memberIdentity == null) {
            memberIdentity = new MemberIdentity();
        }
        memberIdentity.setDeviceId(deviceId);
    }

    public String getDeviceId() {
        if (memberIdentity != null) {
            return memberIdentity.getDeviceId();
        }
        return null;
    }

    public void setDeviceToken(String deviceToken) {
        if (memberIdentity == null) {
            memberIdentity = new MemberIdentity();
        }
        memberIdentity.setDeviceToken(deviceToken);
    }

    public void setUsermark(String usermark) {
        if (memberIdentity == null) {
            memberIdentity = new MemberIdentity();
        }
        memberIdentity.setUsermark(usermark);
    }

    public void setAppType(String appType) {
        if (memberIdentity == null) {
            memberIdentity = new MemberIdentity();
        }
        memberIdentity.setAppType(appType);
    }

    public void setUnionid(String unionid) {
        if (memberIdentity == null) {
            memberIdentity = new MemberIdentity();
        }
        memberIdentity.setUnionid(unionid);
    }

    public void setIsAppLogin(int isAppLogin) {
        if (memberIdentity == null) {
            memberIdentity = new MemberIdentity();
        }
        memberIdentity.setIsAppLogin(isAppLogin);
    }

    public String getAppWxOpenid() {
        if (memberIdentity != null) {
            return memberIdentity.getAppWxOpenid();
        }
        return null;
    }

    public String getMiniAppOpenid() {
        if (memberIdentity != null) {
            return memberIdentity.getMiniAppOpenid();
        }
        return null;
    }


    public String getPortalWxOpenid() {
        if (memberIdentity != null) {
            return memberIdentity.getPortalWxOpenid();
        }
        return null;
    }

    public String getPortalWxMsgOpenid() {
        if (memberIdentity != null) {
            return memberIdentity.getPortalWxMsgOpenid();
        }
        return null;
    }


    public String getMac() {
        if (memberIdentity != null) {
            return memberIdentity.getMac();
        }
        return null;
    }

    public String getUnionid() {
        if (memberIdentity != null) {
            return memberIdentity.getUnionid();
        }
        return null;
    }


    public Long getMob() {
        if (memberIdentity != null) {
            return memberIdentity.getMob();
        }
        return null;
    }

    public void setPassword(String password) {
        if (memberIdentity == null) {
            memberIdentity = new MemberIdentity();
        }
        memberIdentity.setPassword(password);
    }


    public String getRegistSource() {
        if (memberIdentity != null) {
            return memberIdentity.getRegistSource();
        }
        return null;
    }

    public String getDeviceToken() {
        if (memberIdentity != null) {
            return memberIdentity.getDeviceToken();
        }
        return null;
    }

    public String getAppType() {
        if (memberIdentity != null) {
            return memberIdentity.getAppType();
        }
        return null;
    }

    public String getPassword() {
        if (memberIdentity != null) {
            return memberIdentity.getPassword();
        }
        return null;
    }

    public String getOsName() {
        if (memberIdentity != null) {
            return memberIdentity.getOsName();
        }
        return null;
    }

    public void setOsName(String osName) {
        if (memberIdentity == null) {
            memberIdentity = new MemberIdentity();
        }
        memberIdentity.setOsName(osName);
    }


}